package com.chagee.store.operation.server.service.third;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.chagee.base.utils.SoaResponse;
import com.chagee.base.utils.SoaUtil;
import com.chagee.storeManagement.api.event.enums.EventTypeEnum;
import com.chagee.storeManagement.api.event.request.TimerEventRegisterDefaultRequest;
import com.chagee.storeManagement.api.event.service.IEventApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author : hk
 * @Date : 2025/2/26
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class EventThirdService {

	@Resource
	private IEventApi eventApi;


	public void registerDefaultTimerEvent(String bizCode, JSONObject bizData, LocalDateTime timer, EventTypeEnum eventType) {
		try {
			TimerEventRegisterDefaultRequest request = new TimerEventRegisterDefaultRequest();
			request.setBizCode(bizCode);
			request.setBizData(bizData);
			request.setTimer(timer);
			request.setEventType(eventType);
			log.info("EventThirdService.registerDefaultTimerEvent_request:{}", JSONUtil.toJsonStr(request));
			SoaResponse<Void, Void> response = eventApi.registerDefaultTimerEvent(request);
			SoaUtil.unpack(response);
		} catch (Exception e) {
			log.error("EventThirdService.registerDefaultTimerEvent", e);
		}
	}

	public void registerDefaultTimerEvent(List<TimerEventRegisterDefaultRequest> requestList) {
		try {
			log.info("EventThirdService.registerDefaultTimerEvent_list_request:{}", JSONUtil.toJsonStr(requestList));
			SoaResponse<Void, Void> response = eventApi.registerDefaultTimerEvent(requestList);
			SoaUtil.unpack(response);
		} catch (Exception e) {
			log.error("EventThirdService.registerDefaultTimerEvent_list", e);
		}
	}
}
